function transform(ast) {
  let newAst = [];
  /**
   * 遍历AST转换成数组，同时将选择器和值拼接起来
   * @param node AST结点
   * @param result 抽象语法数组
   * @param prefix 当前遍历路径上的选择器名称组成的数组
   */
  function traverse(node, result, prefix) {
    let selector = "";
    if (node.type === "selector") {
      selector = [...prefix, node.value]; //  把选择器合并
      result.push({
        selector: selector.join(" "),
        rules: node.rules.reduce((acc, rule) => {
          acc.push({
            property: rule.property,
            value: rule.value.join(" "),
          });
          return acc;
        }, []),
      });
    }
    for (let i = 0; i < node.children.length; i++) {
      // 有子节点，递归处理
      traverse(node.children[i], result, selector);
    }
  }
  traverse(ast, newAst, []);
  return newAst;
}

module.exports = {
  transform
}